Skip to content

Conversation

@mochow13
Copy link
Contributor

Implements #3353

async def main():
async with agent:
# Access server instructions after connection is established
if server.instructions:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update the example to show those these instructions would be used in the agent instructions, using a dynamic instructions function:

@agent.instructions
async def mcp_server_instructions():
    return server.instructions

When that's called, I believe the server connection is guaranteed to have been established.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the example.

mcp_server.instructions
async with mcp_server:
# The test server doesn't provide instructions, so it should be None
assert mcp_server.instructions is None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we give the test server some instructions so we can verify it actually works? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated - added instructions on the mcp_server.py's test server.


@agent.instructions
async def mcp_server_instructions():
return server.instructions
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a tooltip here to make it clear that the connection is guaranteed to be established by this point.

You can add a tooltip by adding a # (1)! comment, and then a numbered list below the code snippet. You can find some examples elsewhere in the docs, and verify it works by running make docs-serve

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated and tested too, let me know if it works.

@DouweM DouweM changed the title Expose mcp server instructions in MCPServer class as a property Expose MCP server instructions in MCPServer.instructions property Nov 19, 2025
@DouweM DouweM merged commit c096d99 into pydantic:main Nov 19, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants